package com.rpc.tagparser;

import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
import org.springframework.util.StringUtils;
import org.w3c.dom.Element;

/**
 * @author didi
 * @DESCRIPTION
 * @create 2018-06-07 下午5:57
 **/

public class AbstractConfigDefinitionParser extends AbstractSingleBeanDefinitionParser {

    @Override
    protected void doParse(Element element, BeanDefinitionBuilder builder) {
        String interfaceName = element.getAttribute("interface");
        String timeout       = element.getAttribute("timeout");
        String version       = element.getAttribute("version");
        String retries       = element.getAttribute("retries");
        String connections   = element.getAttribute("connections");

        if (StringUtils.hasText(interfaceName)) {
            builder.addPropertyValue("interfaceName", interfaceName);
        }

        if (StringUtils.hasText(timeout)) {
            builder.addPropertyValue("timeout", timeout);
        }

        if (StringUtils.hasText(version)) {
            builder.addPropertyValue("version", version);
        }

        if (StringUtils.hasText(retries)) {
            builder.addPropertyValue("retries", retries);
        }

        if (StringUtils.hasText(connections)) {
            builder.addPropertyValue("connections", connections);
        }

    }
}
